<template>
  <div>
    <div class="modal">
      <div class="modal-bg" @click="RoomCloses"></div>
      <div class="pub-w">
        <div class="rele-title" v-show="tianjiafangjian">添加房号<span @click="RoomCloses">X</span></div>
        <div class="rele-title" v-show="xiugaifangjian">修改房号<span @click="RoomCloses">X</span></div>
        <div class="pub-list">
          <div class="pub-li">
            <div class="pub-title">房间号</div>
            <div class="pub-input"><input type="text" name="" v-model="roomnumber"></div>
          </div>
          <div class="pub-li">
            <div class="pub-title">面积</div>
            <div class="pub-input"><input type="number" name="" v-model="measureofarea"></div>
          </div>
          <div class="pub-li">
            <div class="pub-title">户型</div>
            <div class="pub-input">
              <el-select v-model="huxing" placeholder="请选择" style="width:100%">
                <el-option
                  v-for="item in RoomHuxing"
                  :key="item.id"
                  :label="item.title"
                  :value="item.id">
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="pub-li">
            <div class="pub-title">朝向</div>
            <div class="pub-input">
              <el-select v-model="orientation" placeholder="请选择" style="width:100%">
                <el-option
                  v-for="item in RoomOrientation"
                  :key="item.id"
                  :label="item.title"
                  :value="item.id">
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="pub-li">
            <div class="pub-title">排序值</div>
            <div class="pub-input"><input type="number" name="" v-model="sort"></div>
          </div>
          <div class="pub-li">
            <div class="pub-title">状态</div>
            <div class="pub-input">
              <el-select v-model="status_id" placeholder="请选择" style="width:100%">
                <el-option
                  v-for="item in RoomStatus"
                  :key="item.id"
                  :label="item.title"
                  :value="item.id">
                </el-option>
              </el-select>
            </div>
          </div>
          <!--<div class="pub-li pub-li1">-->
          <!--<span>继续添加</span>  <span>批量导入</span> -->
          <!--</div>-->
          <div class="pub-li pub-li1">
            <button v-show="tianjiafangjian" @click="tianjiaroom">添加</button>
            <button v-show="xiugaifangjian" @click="xiugairoom">修改</button>
            <button @click="RoomCloses">取消</button>
          </div>
        </div>

      </div>
    </div>
  </div>
</template>
<script type="text/babel">
  export default {
    props: {
      lookfangjian: {
        type: Function
      },
      LDmodal: {
        type: Function
      },
      RoomClose: {
        type: Function
      },
      LCid: {
        type: Number
      },
      FJid: {
        type: Number
      }
    },
    data() {
      return {
        tianjiafangjian: true,
        xiugaifangjian: false,
        roomnumber: '',
        sort: '',
        huxing: '',
        measureofarea: '',
        orientation: '',
        RoomOrientation: [],
        RoomHuxing: [],
        RoomStatus: [],
        status_id: ''
      }
    },
    methods: {
      RoomCloses() {
        this.roomnumber = '';
        this.sort = '';
        this.huxing = '';
        this.measureofarea = '';
        this.orientation = '';
        this.RoomClose();
      },
      TJgoFJ() {
        this.tianjiafangjian = true;
        this.xiugaifangjian = false;
      },
      XGgoFJ() {
        this.tianjiafangjian = false;
        this.xiugaifangjian = true;
      },
      tianjiaroom() {
        let that = this;
        that.$http.post('/newapi/Premisesroom/add', {
          premisesfloor_id: that.LCid,
          title: that.roomnumber,
          sort: that.sort,
          huxing: that.huxing,
          measureofarea: that.measureofarea,
          orientation: that.orientation,
          status_id: that.status_id
        }).then(res => {
          if (res.data.status === 200) {
            that.lookfangjian(that.LCid);
            that.RoomClose();
            that.$store.state.messageString = res.data.message;
            that.LDmodal();
            that.roomnumber = '';
            that.sort = '';
            that.huxing = '';
            that.measureofarea = '';
            that.orientation = '';
            that.status_id = ''
          } else {
            that.$store.state.messageString = res.data.message;
            that.LDmodal();
          }
        }).catch(err => {
          console.log(err)
        })
      },
      xiugairoom() {
        // alert('aaa');
        let that = this;
        // console.log(this.FJid);
        that.$http.post('/newapi/Premisesroom/add', {
          id: that.$store.state.FJid,
          premisesfloor_id: that.LCid,
          title: that.roomnumber,
          sort: that.sort,
          huxing: that.huxing,
          measureofarea: that.measureofarea,
          orientation: that.orientation,
          status_id: that.status_id
        }).
          then(res => {
            // alert('aaaa');
            // console.log('房间'+':'+that.FJid+';'+'楼层'+';'+that.LCid);
            if (res.data.status === 200) {
              that.RoomClose();
              that.lookfangjian(that.LCid);
              this.$store.state.messageString = res.data.message;
              this.LDmodal();
              that.roomnumber = '';
              that.sort = '';
              that.huxing = '';
              that.measureofarea = '';
              that.orientation = '';
              that.status_id = '';
            } else {
              this.$store.state.messageString = res.data.message;
              this.LDmodal();
            }
          }).catch(err => {
          console.log(err)
        })
      },
      gettitle() {
        let that = this;
        that.$http.get('/newapi/Premisesroom/details', {
          params: {
            id: that.$store.state.FJid
          }
        }).then(res => {
          console.log(res);
          that.roomnumber = res.data.res.title;
          that.measureofarea = res.data.res.measureofarea; //面积
          that.orientation = res.data.res.orientation;
          that.huxing = res.data.res.huxing;
          that.sort = res.data.res.sort;
          that.status_id = res.data.res.status_id;
        }).catch(err => {
          console.log(err)
        });
      }
    },
    created() {
      let that = this;
      that.$http.get('/newapi/Premisesroom/lists', {}).then(res => {
        console.log(res.data.res)
        that.RoomHuxing = res.data.res.RoomHuxing;
        that.RoomOrientation = res.data.res.RoomOrientation;
        that.RoomStatus = res.data.res.RoomStatus;
      }).catch(err => {
      })
    },
    computed: {
      roomID() {
        return this.fangjianID
      }
    }
  }
</script>
<style scoped>
  .pub-li1 {
    width: 100% !important
  }

  .pub-li1 span {
    float: left;
    font-size: 1.2em
  }

  .pub-li1 span:nth-child(2) {
    float: right;
  }

  .pub-li button {
    width: 100px;
    font-size: 1.1em;
    background: #ed7d31;
    color: #ffffff;
    border: none;
    float: left;
    border-radius: 5px;
    line-height: 35px;
  }

  .pub-li button:last-child {
    float: right;
    background: none;
    border: 1px solid #ed7d31;
    color: #ed7d31
  }

  .pub-list {
    width: 94%;
    padding: 0 3%;
    float: left;
    text-align: center;
    margin-top: 40px;
  }

  .pub-input {
    width: 70%;
    float: left;
  }

  .pub-input input {
    width: 100%;
    line-height: 27px;
    height: 27px;
    float: left;
    box-sizing: border-box;
    border-radius: 5px;
    border: 1px solid #d3d3d3;
  }

  .pub-li {
    margin-top: 20px;
    width: 50%;
    float: left;
  }

  .pub-title {
    width: 30%;
    line-height: 27px;
    text-align: center;
    font-size: 1.1em;
    float: left;
  }

  .pub-w {
    width: 30%;
    left: 35%;
    /*height: 340px;*/
    padding-bottom: 20px;
    top: 50%;
    margin-top: -170px;
    overflow: hidden;
    background: #ffffff;
    border-radius: 5px;
    position: absolute;
    z-index: 10;
  }
</style>
